package priv.pront.code.national.acwing.dp.linear.lis;

import java.util.Scanner;

public class Acwing1017_怪盗基德的滑翔翼 {

    static int[] a, dp1, dp2;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        while (k-- > 0) {
            int n = scanner.nextInt();
            a = new int[n + 1];
            dp1 = new int[n + 1];
            dp2 = new int[n + 1];
            dp1[1] = 1;
            dp2[1] = 1;
            for (int i = 1; i <= n; i++) a[i] = scanner.nextInt();
            for (int j = 2; j <= n; j++) {
                int max1 = 0;
                int max2 = 0;
                for (int t = 1; t < j; t++) {
                    if (a[t] > a[j]) {
                        max1 = Math.max(max1, dp1[t]);
                    }
                    if (a[t] < a[j]) {
                        max2 = Math.max(max2, dp2[t]);
                    }
                }
                dp1[j] = max1 + 1;
                dp2[j] = max2 + 1;
            }
            int ans1 = 0;
            int ans2 = 0;
            for (int i = 1;i <= n ;i++) {
                ans1 = Math.max(ans1, dp1[i]);
            }
            for (int i = 1;i <= n ;i++) {
                ans2 = Math.max(ans2, dp2[i]);
            }
            System.out.println(Math.max(ans1, ans2));
        }
    }
}
